<?php
namespace Admin\Form;

use User\Entity\User as UserEntity;
use Zend\Form\Fieldset;
use Zend\InputFilter\InputFilterProviderInterface;
use Zend\Stdlib\Hydrator\ClassMethods;
use Admin\Form\CreateUserFormFilter;

class UpdateUserFieldset extends Fieldset implements InputFilterProviderInterface
{
    public function __construct()
    {
        parent::__construct('update_user');

        $this
            ->setHydrator(new ClassMethods())
            ->setObject(new UserEntity())
        ;

        $this->add(array(
            'name' => 'firstname',
            'options' => array(
                'label' => 'First name',
            ),
            'attributes' => array(
                'type' => 'text',
                'class' => 'form-control col-xs-12',
                'placeholder' => 'First name'
            ),
        ));

        $this->add(array(
            'name' => 'lastname',
            'options' => array(
                'label' => 'Last name',
            ),
            'attributes' => array(
                'type' => 'text',
                'class' => 'form-control col-xs-12',
                'placeholder' => 'Last name'
            ),
        ));


        $this->add(array(
            'name' => 'email',
            'options' => array(
                'label' => 'Email',
            ),
            'attributes' => array(
                'type' => 'text',
                'class' => 'form-control col-xs-12',
                'placeholder' => 'Email'
            ),
        ));

        $this->add(array(
            'type' => 'Admin\Form\RoleUserFieldset',
            'options' => array(
                'use_as_base_fieldset' => true,
            ),
        ));

        $this->add(array(
            'name' => 'phone',
            'options' => array(
                'label' => 'Phone',
            ),
            'attributes' => array(
                'type' => 'text',
                'class' => 'form-control col-xs-12',
                'placeholder' => 'Phone'
            ),
        ));

        $this->add(array(
            'name' => 'address',
            'options' => array(
                'label' => 'address',
            ),
            'attributes' => array(
                'type' => 'textarea',
                'class' => 'form-control col-xs-12',
                'placeholder' => 'address'
            ),
        ));



        $this->add(array(
            'name' => 'password',
            'options' => array(
                'label' => 'Password',
            ),
            'attributes' => array(
                'type' => 'password',
                'class' => 'form-control col-xs-12',
                'placeholder' => 'password'
            ),
        ));

        $this->add(array(
            'name' => 'password_verify',
            'options' => array(
                'label' => 'Password Verify',
            ),
            'attributes' => array(
                'type' => 'password',
                'class' => 'form-control col-xs-12',
                'placeholder' => 'password verify'
            ),
        ));


        $this->add(array(
            'type' => 'Admin\Form\AvatarUserFieldset',
            'options' => array(
                'use_as_base_fieldset' => true,
            ),
        ));

        /*
        $this->add(array(
            'name' => 'avatar',
            'options' => array(
                'label' => 'avatar',
            ),
            'attributes' => array(
                'type' => 'file',
                'class' => 'form-control col-xs-12',
                'placeholder' => 'avatar'
            ),
        ));*/


        $this->add(array(
            'name' => 'user_id',
            'type' => 'Zend\Form\Element\Hidden',
            'attributes' => array(
                'type' => 'hidden'
            ),
        ));

    }

    /**
     * @return array
     */
    public function getInputFilterSpecification() {
        return array(
            'firstname' => array(
                'name'       => 'firstname',
                'required'   => true,
                'filters' => array(
                    array('name' => 'StripTags') ,
                    array('name' => 'StringTrim') ,
                ),
                'validators' => array(
                    /*array(
                        'name' => 'NotEmpty',
                        'options' => array(
                            'messages' => array(
                                \Zend\Validator\NotEmpty::IS_EMPTY => static::MESSAGE_EMPTY,
                            ),
                        ),
                    ),*/
                    array(
                        'name' => 'StringLength' ,
                        'options' => array(
                            'encoding' => 'UTF-8' ,
                            'min' => 2 ,
                            'max' => 50 ,
                            /*'messages' => array(
                                'stringLengthTooShort' => 'fisrtname tu 2 ki tu tro len',
                                'stringLengthTooLong' => 'fisrtname phai nho hon 50 ki tu.',
                            )*/
                        ) ,
                    ),
                ),
            ),

            'lastname' => array(
                'name'       => 'lastname',
                'required'   => true,
                'filters' => array(
                    array('name' => 'StripTags') ,
                    array('name' => 'StringTrim') ,
                ),
                'validators' => array(
                    /*array(
                        'name' => 'NotEmpty',
                        'options' => array(
                            'messages' => array(
                                \Zend\Validator\NotEmpty::IS_EMPTY => static::MESSAGE_EMPTY,
                            ),
                        ),
                    ),*/
                    array(
                        'name'    => 'StringLength',
                        'options' => array(
                            'encoding' => 'UTF-8' ,
                            'min' => 2,
                            'max' => 50,
                        ),
                        /*'messages' => array(
                            'stringLengthTooShort' => 'lastname tu 2 ki tu tro len',
                            'stringLengthTooLong' => 'lastname phai nho hon 50 ki tu.',
                        )*/
                    ),
                    //$this->usernameValidator,
                ),
            ),

            'email' => array(
                'name'       => 'email',
                'required'   => true,
                'validators' => array(
                    array(
                        'name' => 'EmailAddress',
                        'options' => array(
                            /*'messages' => array(
                                 'emailAddressInvalidFormat' => 'email khong dung dinh dang'
                                //\Zend\Validator\NotEmpty::IS_EMPTY => 'Email address is required',
                            )*/
                        )
                    ),
                    //$this->emailValidator
                ),
            ),

            'password' => array(
                'name'       => 'password',
                'required'   => true,
                'filters'    => array(array('name' => 'StringTrim')),
                'validators' => array(
                    array(
                        'name'    => 'StringLength',
                        'options' => array(
                            'min' => 6,
                            /*'messages' => array(
                               'stringLengthTooShort' => 'password phai it nhat la 6 ki tu.',
                            ),*/
                        ),
                    ),
                ),
            ),
            'password_verify' => array(
                'name'       => 'password_verify',
                'required'   => true,
                'filters'    => array(array('name' => 'StringTrim')),
                'validators' => array(
                    array(
                        'name'    => 'StringLength',
                        'options' => array(
                            'min' => 6,
                        ),
                    ),
                    array(
                        'name'    => 'Identical',
                        'options' => array(
                            'token' => 'password',
                            /*'messages' => array(
                                'notSame' => "password khong khop.",
                                'missingToken' => "password khong khop.",
                            )*/
                        ),
                    ),
                ),
            ),
            
        );
    }
} 